package com.yunzhong.appointment.essentialinformation.service.impl;

import com.yunzhong.appointment.entity.Noticeboard;
import com.yunzhong.appointment.essentialinformation.service.INoticeService;
import com.yunzhong.appointment.mapper.NoticeboardMapper;
import com.yunzhong.appointment.util.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @author 王仁海
 * @author ThinkPad
 * @desc 公告模型层
 */
@Service
public class NoticeServiceImpl implements INoticeService {

    /**
     * 依赖注入公告模型层的Mapper接口
     */
    @Autowired
    private NoticeboardMapper noticeboardMapper;

    @Override
    public List<Noticeboard> queryNotice(PageData pd) {
        pd.setPageData(pd);
        System.out.println("pd-----------" + pd);
        return noticeboardMapper.queryNotice(pd);
    }

    @Override
    public Noticeboard queryById(String id) {
        return noticeboardMapper.selectByPrimaryKey(id);
    }

    @Override
    public int delete(String[] ids) {
        int tiao = 0;
        for (int i = 0; i < ids.length; i++) {
            tiao = noticeboardMapper.deleteByPrimaryKey(ids[i]);
        }
        return tiao;
    }

    @Override
    public int save(Noticeboard gg) {
        gg.setNoticeId(UUID.randomUUID().toString());
        gg.setNoticeTime(new Date());
        return noticeboardMapper.insert(gg);
    }

    @Override
    public int edit(Noticeboard gg) {
        return noticeboardMapper.updateByPrimaryKeySelective(gg);
    }

}
